package com.dev.mainual.throwable.optimize;

/**
 * ClassName: ExceptionOptimizeDemo
 * Description: 异常优化点
 * Date: 2019/1/25 9:33 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class ExceptionOptimizeDemo {

    /**
     * try catch 禁止用在循环内部
     */
    public static void test1() {
        long start = System.currentTimeMillis();
        int a = 0;
        for (int i = 0; i < 1000000000; i++) {
            try {
                a++;
            } catch (Exception e) {
            }
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    /**
     * try catch 在循环体外
     */
    public static void test2() {
        long start = System.currentTimeMillis();
        int a = 0;
        try {
            for (int i = 0; i < 1000000000; i++) {
                a++;
            }
        } catch (Exception e) {
        }
        System.out.println(System.currentTimeMillis() - start);
    }
}
